<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layouts/template.xhtml">
	<ui:define name="body">
		<h:form id="form" acceptcharset="ISO-8859-1">
			<f:metadata>
				<f:viewParam name="param" value="#{associationBean.param}"/>
			</f:metadata>

			<p:panel header="#{msgs['massai.association.header.register']}">
				<h:panelGrid rendered="#{associationBean.department.id ne null}" style="margin: 0 0 10px 0; color: red;">
					<h:panelGroup>
						<p:selectBooleanCheckbox tabindex="1" label="#{msgs['massai.association.lockedDepartment']}" value="#{associationBean.statusDepartment}">
							<p:ajax event="change" global="false" />
						</p:selectBooleanCheckbox>
						<p:outputLabel value="#{msgs['massai.association.lockedDepartment']}" style="padding: 0 0 3px 10px;" />
					</h:panelGroup>
				</h:panelGrid>
			
				<h:panelGrid columns="3">
					<h:panelGrid>
						<p:outputLabel for="codEmp" value="#{msgs['massai.association.codeEmp']}" />
						<p:inputText id="codEmp" value="#{associationBean.department.codeEmp}" required="true" requiredMessage="Cód. Empresa #{msgs['common.required.field']}" 
							style="width: 90px; text-align: right;" onkeypress="return numberOnly(this, event)" maxlength="4" tabindex="1">
							<p:ajax event="change" listener="#{associationBean.findDepartmentFORTES()}" update="form" />
						</p:inputText>
					</h:panelGrid>

					<h:panelGrid>
						<p:outputLabel for="codDepart" value="#{msgs['massai.association.codeDepart']}" />
						<p:inputText id="codDepart" value="#{associationBean.department.codeDepartment}" required="true" requiredMessage="Cód. Departamento #{msgs['common.required.field']}"
							style="width: 150px; text-align: right;" onkeypress="return numberOnly(this, event)" maxlength="10" tabindex="2">
							<p:ajax event="change" listener="#{associationBean.findDepartmentFORTES()}" update="form" />
						</p:inputText>
					</h:panelGrid>

					<h:panelGrid>
						<p:outputLabel for="codSienge" value="#{msgs['massai.association.codeSienge']}" />
						<p:inputText id="codSienge" value="#{associationBean.department.codeSienge}" required="true" requiredMessage="Cód. Sienge #{msgs['common.required.field']}"
							style="width: 80px; text-align: right;" onkeypress="return numberOnly(this, event)" maxlength="9" tabindex="3" />
					</h:panelGrid>
				</h:panelGrid>

				<h:panelGrid>
					<p:outputLabel for="name" value="#{msgs['massai.association.name']}" />
					<p:inputText id="name" value="#{associationBean.department.nameDepartment}" required="true" 
						requiredMessage="Nome #{msgs['common.required.field']}" style="width: 360px;" 
						maxlength="150" disabled="true" readonly="true" />
				</h:panelGrid>

				<h:panelGrid>
					<p:outputLabel for="alternativeName" value="#{msgs['massai.association.alternativeName']}" />
					<p:inputText id="alternativeName" value="#{associationBean.department.alternativeName}" required="true" 
						requiredMessage="Apelido #{msgs['common.required.field']}" style="width: 360px;" 
						maxlength="150" tabindex="4" />
				</h:panelGrid>

				<p:spacer height="25px" />

				<fieldset>
					<legend> <p:outputLabel value="#{msgs['massai.association.collaboratorsAssociated']}" /> </legend>
					<h:panelGrid columns="2">
						<h:panelGrid>
							<p:outputLabel for="collaborator" value="#{msgs['massai.association.collaborator']}" />
							<p:selectOneMenu id="collaborator" value="#{associationBean.collaborator}" 
								style="width: 250px;" tabindex="5" converter="entityConverter" >
								<f:selectItems value="#{associationBean.listCollaborators()}" />
								<p:ajax event="change" global="false" />
							</p:selectOneMenu>
						</h:panelGrid>

						<h:panelGrid>
							<p:spacer height="14" />
							<p:commandButton tabindex="6" value="#{msgs['common.add']}" process="@form"
								ajax="true" immediate="true" actionListener="#{associationBean.addCollaborator()}" 
								update="dataTableCollaborator" />
						</h:panelGrid>
					</h:panelGrid>

					<p:spacer height="10px" />

					<p:dataTable id="dataTableCollaborator" emptyMessage="#{msgs['common.no.record.found']}" 
						value="#{associationBean.department.collaborators}" var="collaborator" sortMode="multiple" rows="5" paginator="true"
		                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
		                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false"
		                rowIndexVar="row">

						<p:column headerText="#{msgs['massai.association.name']}" sortBy="#{collaborator.nameCollaborator}">
	                        <h:outputText value="#{collaborator.nameCollaborator}" />
	                    </p:column>
	
	                    <p:column headerText="#{msgs['massai.association.email']}" sortBy="#{collaborator.email}" width="180">
	                        <h:outputText value="#{collaborator.email}" />
	                    </p:column>
	                    
	                    <p:column headerText="#{msgs['massai.association.login']}" sortBy="#{collaborator.username}" width="120">
	                        <h:outputText value="#{collaborator.username}" />
	                    </p:column>

	                    <p:column headerText="#{msgs['massai.association.status']}" sortBy="#{collaborator.active}" width="100">
	                        <h:outputText value="#{collaborator.active.description}" />
	                    </p:column>

						<p:column headerText="#{msgs['common.delete']}" width="60" style="text-align: center;">
							<h:commandLink id="delete" tabindex="7" immediate="true"
								onclick="if (!window.confirm('Deseja remover esse colaborador?') ) {return false}" 
				            	actionListener="#{associationBean.removeCollaborator(collaborator, row)}">
								<img src="#{facesContext.externalContext.requestContextPath}/images/ico_remove.png" 
									width="16" height="16" border="0" name="#{msgs['common.delete']}" 
									alt="#{msgs['common.delete']}" id="icoRemove" title="#{msgs['common.delete']}" />
							</h:commandLink>
						</p:column>
					</p:dataTable>
				</fieldset>

				<p:spacer height="25px" />

				<h:panelGrid style="width: 100%;">
					<h:panelGrid style="float: right;" columns="2">
						<p:commandButton value="#{msgs['common.back']}" style="padding: 1px !important;"
							action="associationConsult" ajax="false" immediate="true" tabindex="7" />

						<p:commandButton tabindex="8" value="#{msgs['common.save']}"
							actionListener="#{associationBean.save()}" ajax="false" 
							style="margin-right: 5px;" styleClass="buttonSave" update=":form"
							rendered="#{sessionBean.showAction('adminAssociation', 'insert')}" />
					</h:panelGrid>
				</h:panelGrid>
			</p:panel>
		</h:form>
	</ui:define>
</ui:composition>
</html>